package com.gupaoedu.design.template.dao;

import com.gupaoedu.design.template.JdbcTemplate;
import com.gupaoedu.design.template.entity.Member;
import com.gupaoedu.design.template.mapper.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * <p></p>
 *
 * @author Andy
 * @date 2018/3/13.
 */
public class MemberDao {

    private JdbcTemplate jdbcTemplate;

    public List<?> query(){
        String sql = "select * from t_member";
        return jdbcTemplate.executeQuery(sql, new RowMapper() {
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                Member member = new Member();
                member.setFirstName(rs.getString("firstName"));
                member.setAge(rs.getInt("age"));
                member.setPassword(rs.getString("password"));
                member.setAddr(rs.getString("addr"));
                member.setNikeName(rs.getString("nikeName"));
                return member;
            }
        });
    }
}
